package com.config.demo;

import com.config.demo.model.Car;
import com.config.demo.model.User;
import com.config.demo.myconfig.MyConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;


@SpringBootApplication
public class DemoConfigApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext context = SpringApplication.run(DemoConfigApplication.class, args);

        String[] names = context.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }

        Car car1 = context.getBean("getCar", Car.class);
        Car car2 = context.getBean("getCar", Car.class);
        System.out.println("车1" + car1);
        System.out.println("车2" + car2);
        System.out.println("车是否相等" + (car1 == car2));

        //如果@Configuration(proxyBeanMethods = true)代理对象调用方法。SpringBoot总会检查这个组件是否在容器中有。
        //保持组件单实例
        MyConfig config = context.getBean(MyConfig.class);
        User user1 = config.getUser();
        User user2 = config.getUser();
        System.out.println("用户否相等" + (user1 == user2));

    }

}
